package com.karson.service.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.karson.common.constants.Constants;
import com.karson.common.exception.AsmrException;
import com.karson.common.model.AlbumAuthor;
import com.karson.common.model.CirclesInfo;
import com.karson.service.service.CirclesInfoService;
import com.karson.service.dao.CirclesInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author ZKS
* @description 针对表【ar_circles_info(社群信息表)】的数据库操作Service实现
* @createDate 2025-08-05 17:38:30
*/
@Service
public class CirclesInfoServiceImpl extends ServiceImpl<CirclesInfoMapper, CirclesInfo>
    implements CirclesInfoService{
    @Autowired
    private CirclesInfoMapper circlesInfoMapper;
    @Override
    public IPage<CirclesInfo> pageList(IPage<CirclesInfo> circlesInfoIPage, String keyword) {
        return circlesInfoMapper.pageList(circlesInfoIPage,keyword);
    }
    @Override
    public Boolean operationWorkCount(Integer id, Integer num, String type) {
        UpdateWrapper<CirclesInfo> updateWrapper = new UpdateWrapper<>();
        if (Constants.WORK_COUNT_ADD.equals(type)){
            updateWrapper.setSql(StrUtil.format("work_count = work_count + {}", num));
        }
        if (Constants.WORK_COUNT_DELETE.equals(type)){
            updateWrapper.setSql(StrUtil.format("work_count = work_count - {}", num));
            updateWrapper.last(StrUtil.format(" and (work_count - {} >= 0)", num));
        }
        updateWrapper.eq("id",id);
        boolean update = update(updateWrapper);
        if (!update) {
            throw new AsmrException("更新标签数量失败，标签Id = "+ id);
        }
        return true;
    }
}




